Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc++] Remove unnecessary assignments #78678

Closed

Conversation

AdvenamTacet
Copy link
Member

This commit removes unnecessary assignments, which already happen in called functions.

This PR is untested, I just spotted it trying to understand why #75882 is causing problems with buildbots.

This commit removes unnecessary assignments, which already happen in called functions.
@AdvenamTacet AdvenamTacet added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jan 19, 2024
@AdvenamTacet AdvenamTacet requested review from philnik777 and a team January 19, 2024 07:12
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 19, 2024

@llvm/pr-subscribers-libcxx

Author: Tacet (AdvenamTacet)

Changes

This commit removes unnecessary assignments, which already happen in called functions.

This PR is untested, I just spotted it trying to understand why #75882 is causing problems with buildbots.


Full diff: https://github.com/llvm/llvm-project/pull/78678.diff

1 Files Affected:

  • (modified) libcxx/include/vector (+7-16)
diff --git a/libcxx/include/vector b/libcxx/include/vector
index e9dd57055cb112d..81c70394fd8ec37 100644
--- a/libcxx/include/vector
+++ b/libcxx/include/vector
@@ -1459,26 +1459,20 @@ vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x) {
 template <class _Tp, class _Allocator>
 _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI void
 vector<_Tp, _Allocator>::push_back(const_reference __x) {
-  pointer __end = this->__end_;
-  if (__end < this->__end_cap()) {
+  if (this->__end_ < this->__end_cap()) {
     __construct_one_at_end(__x);
-    ++__end;
   } else {
-    __end = __push_back_slow_path(__x);
+    __push_back_slow_path(__x);
   }
-  this->__end_ = __end;
 }
 
 template <class _Tp, class _Allocator>
 _LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI void vector<_Tp, _Allocator>::push_back(value_type&& __x) {
-  pointer __end = this->__end_;
-  if (__end < this->__end_cap()) {
+  if (this->__end_ < this->__end_cap()) {
     __construct_one_at_end(std::move(__x));
-    ++__end;
   } else {
-    __end = __push_back_slow_path(std::move(__x));
+    __push_back_slow_path(std::move(__x));
   }
-  this->__end_ = __end;
 }
 
 template <class _Tp, class _Allocator>
@@ -1503,16 +1497,13 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 inline
     void
 #endif
     vector<_Tp, _Allocator>::emplace_back(_Args&&... __args) {
-  pointer __end = this->__end_;
-  if (__end < this->__end_cap()) {
+  if (this->__end_ < this->__end_cap()) {
     __construct_one_at_end(std::forward<_Args>(__args)...);
-    ++__end;
   } else {
-    __end = __emplace_back_slow_path(std::forward<_Args>(__args)...);
+    __emplace_back_slow_path(std::forward<_Args>(__args)...);
   }
-  this->__end_ = __end;
 #if _LIBCPP_STD_VER >= 17
-  return *(__end - 1);
+  return *(this->__end_ - 1);
 #endif
 }
 

Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per my comment, I think we don't want to move forward with this.

@@ -1459,26 +1459,20 @@ vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x) {
template <class _Tp, class _Allocator>
_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI void
vector<_Tp, _Allocator>::push_back(const_reference __x) {
pointer __end = this->__end_;
if (__end < this->__end_cap()) {
if (this->__end_ < this->__end_cap()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added in 6fe4e03, which optimized std::vector. Removing those would be a performance regression. Unfortunately we have benchmarks but no automated performance regression tests right now.

@AdvenamTacet
Copy link
Member Author

@ldionne Interesting, thx for the feedback, do we want to keep updating the same value in Transactions? Same work is done twice here, maybe we should remove analogical code in transaction class?

@AdvenamTacet AdvenamTacet deleted the vector-push_back-refactor branch January 22, 2024 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants